package cn.lhl.sys.event;

import org.springframework.context.event.*;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class MyEventLisner {

	@EventListener
	@Async // 需要@EnableAsync
	public void onApplicationEventAsync(MyEvent event) {
		println("@EventListener（异步） - 接收到 Spring ContextRefreshedEvent");
	}

	@EventListener
	@Order(2)
	public void onApplicationEvent(MyEvent event) {
		println("@EventListener - 接收到 Spring ContextStartedEvent1");
	}
	@EventListener
	@Order(1) // 可以使用@Order控制顺序，数字越小越先执行
	public void onApplicationEvent2(MyEvent event) {
		println("@EventListener - 接收到 Spring ContextStartedEvent2");
	}

	private static void println(Object printable) {
		System.out.printf("[线程：%s] : %s\n", Thread.currentThread().getName(), printable);
	}

}
